This was one of the first projects that I did, this is through the CS50 course. I only did the implementation of the filters which include, edge detection, grayscale, reflect, blur. There is a part of the program I will not be showing the reason being because it was given to me, that part of the code read in the image as an objects so I could then read through the rows of pixels. To see my implimentation of memory allocation and object creation in the C language take a look at Generation Generator project.
This is the results of my implimentation of an edge detection program with the C language.
Now the breakdown.
First is the loop through of each pixel of the image, I did this with for loops running through the height
and width of the image.
Then the rest is passed into a single function... I really would like to rework this but I think the ametuer
state of this program excentuates growth.
get_edge() Function
The start of the get_edge() function defines some of the variables
The RGB value store at position (x,y) within the image using, RGBTRIPLE Gx[3][3]
and RGBTRIPLE Gy[3][3]. Having the 3x3 array allows access to all of the "pixels"
to the top, right, bottom and left of the pixel that has been passed into the function.
This is done through the two for loops.
Next a zero varible is defined for zeroing out the three rgb variables at a pixel.
Finally the Int value stores the three rgb values to the left, right, up and down of the
current pixel.
After the variables are created, the red, green, blue values are added into the gxleft,
gxright, gyup, gydown.
This is done for each "row" of the image.
The last operation in these for loops catches any values that have gone outside the max
and min values allowed and sets them.
Finding Edges
After all of the rgb values are gathered the comparison of these values to find edges begins
The dif and largest_dif will be used to find the largest color value difference to
the right or above.
All of the values within the value array are calculated.
This loop is only used for GxLeft and GxDown
values. They are compared against the GxRight and GxUp
respectively.
After looping through all of the value there will be one value (largest_dif)
which is then assigned to the new image RGB values at that pixel.
It then returns to the image loop and loops through all of the pixels.
Summary
In the end this method does not work very well. Although it worked fairly well on
image first shown there was a couple other images it was tested on that had strange
edge detection or one color came through stronger than the others.
Click Here for the full code.